﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;

namespace Reporter.Controls
{
    /// <summary>
    /// Provides a circular progress bar
    /// </summary>
    public partial class CircularProgressBar : INotifyPropertyChanged
    {
        #region Data
        private readonly DispatcherTimer animationTimer;
        private Storyboard indeterminedLoop;        

        private int _value;

        public int Value
        {
            get { return _value; }
            set
            {
                if (this._value != value)
                {
                    this._value = value;
                    this.NotifyPropertyChanged("Value");
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public CircularProgressBar()
        {
            InitializeComponent();
            this.indeterminedLoop = ((Storyboard)this.CircleProgress.Resources["IndeterminedLoop"]);
            //if (RenderCapability.Tier <  0x20000)
            {
               
                this.indeterminedLoop.SetValue(Timeline.DesiredFrameRateProperty, 10);
            }

            this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(CircularProgressBar_IsVisibleChanged);
        }

        void CircularProgressBar_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue == true && (bool)e.OldValue != true && this.indeterminedLoop != null)
            {
                    this.indeterminedLoop.Begin();
            }
            else
            {
                this.indeterminedLoop.Stop();
            }
        }
    }
}
